//
//  GameMenu.m
//  lianliankan
//
//

#import "GameMenu.h"
#import "LevelScene.h"
#import "SettingScene.h"

@implementation GameMenu

+(CCScene *) scene
{
	// 'scene' is an autorelease object.
	CCScene *scene = [CCScene node];
	
	// 'layer' is an autorelease object.
	GameMenu *layer = [GameMenu node];
	
	// add layer as a child to scene
	[scene addChild: layer];
	
	// return the scene
	return scene;
}

- (id)init
{
	if((self = [super init]))
	{
		// 屏幕尺寸
		CGSize screenSize = [[CCDirector sharedDirector] winSize];
		
		// 背景图片
		CCSprite *bg = [CCSprite spriteWithFile:@"background.png"];
		bg.position = ccp(screenSize.width / 2, screenSize.height / 2);
		[self addChild:bg z:-1 tag:1];
		
		// 菜单标题
		CCLabelTTF *menuTitle = [CCLabelTTF labelWithString:@"菜单" fontName:@"Marker Felt" fontSize:32];
		menuTitle.position = ccp(screenSize.width /2 , screenSize.height - 80);
		[self addChild:menuTitle z:0 tag:2];
		
		// 菜单
		[CCMenuItemFont setFontName:@"Arial"];
		[CCMenuItemFont setFontSize:25];
		
		CCMenuItem *levelMenu = [CCMenuItemFont itemFromString:@"进入游戏" target:self selector:@selector(goLevelMenuScene)];
		CCMenuItem *settingMenu = [CCMenuItemFont itemFromString:@"游戏设置" target:self selector:@selector(goSettingMenuScene)];
		CCMenu *menu = [CCMenu menuWithItems:levelMenu, settingMenu, nil];
		[menu alignItemsVerticallyWithPadding:30];
		[self addChild:menu z:1 tag:3];
	}
	return self;
}


// 跳转到关卡场景
- (void) goLevelMenuScene
{
	CCScene *sc = [CCScene node];
	[sc addChild:[LevelScene node]];
	
	[[CCDirector sharedDirector] replaceScene:sc];
}

// 跳转到设置场景
- (void) goSettingMenuScene
{
	CCScene *sc = [CCScene node];
	[sc addChild:[SettingScene node]];
	
	[[CCDirector sharedDirector] pushScene:sc];
}

// 释放资源
- (void) dealloc
{
	CCLOG(@"%@:%@", NSStringFromSelector(_cmd), self);
	[super dealloc];
}

@end
